package com.wen.center.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by LAIO on 2018/6/3.
 */
public class CoderUtils {


    /**
     * MD5加密
     *
     * @param text 加密明文
     * @return 加密密文 base64 字符串
     */
    public static String encoderMD5(String text) {
        if (text == null) {
            text = "";
        }
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] encoderBytes = messageDigest.digest(text.getBytes());
            BASE64Encoder base64Encoder = new BASE64Encoder();
            return base64Encoder.encode(encoderBytes);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
